home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / CAMERA / CAMS / CAMSFAC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  3.3 KB  |  135 lines

  1. /* $Id: CamSFac.cpp 1.1 1996/07/18 23:54:39 Damien Exp $ */
  2. //
  3. // Copyright (c) 1995, Ray Dream, Inc. All rights reserved.
  4.  
  5. // COM Example of a Spherical Camera
  6. // Class Factory
  7. //
  8.  
  9. #ifndef __CAMSFAC__
  10. #include "CAMSFac.h"
  11. #endif
  12.  
  13. #ifndef __COMCAMS__
  14. #include "ComCAMS.h"
  15. #endif
  16.  
  17. #ifndef __CAMSDLL__
  18. #include "CAMSdll.h"
  19. #endif
  20.  
  21.  
  22. SphereCameraClassFactory::SphereCameraClassFactory() {
  23.   m_cRef=0L;  // just created so no reference used
  24.   return;
  25.   }
  26.  
  27.  
  28. SphereCameraClassFactory::~SphereCameraClassFactory() {
  29.   return;
  30.   }
  31.  
  32. // IUnknown methods of SphereCameraClassFactory                                                
  33. STDMETHODIMP SphereCameraClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv) {
  34.   *ppv=NULL;
  35.  
  36.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  37.       *ppv=(LPVOID)this;
  38.  
  39.   if (*ppv!=NULL) {
  40.     ((LPUNKNOWN)*ppv)->AddRef(); // Add reference if we give a pointer
  41.     return NOERROR;
  42.     }
  43.   else {
  44.       return ResultFromScode(E_NOINTERFACE);
  45.       }
  46.   }
  47.  
  48.  
  49. STDMETHODIMP_(ULONG) SphereCameraClassFactory::AddRef() {
  50.   return ++m_cRef;
  51.   }
  52.  
  53.  
  54. STDMETHODIMP_(ULONG) SphereCameraClassFactory::Release() {
  55.   ULONG        UnreleaseRef;
  56.  
  57.   UnreleaseRef=--m_cRef;
  58.  
  59.   if (m_cRef == 0)
  60.       delete this; // No reference left, so delete the SphereCameraClassFactory
  61.  
  62.   return UnreleaseRef;
  63.   }
  64.  
  65. /*
  66.  * SphereCameraClassFactory::CreateInstance
  67.  *
  68.  * Parameters:
  69.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  70.  *                  being used in an aggregation.
  71.  *  riid            REFIID identifying the interface the caller
  72.  *                  desires to have for the new object.
  73.  *  ppvObj          LPVOID FAR* in which to store the desired
  74.  *                  interface pointer for the new object.
  75.  *
  76.  * Return Value:
  77.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  78.  *                  if we cannot support the requested interface.
  79.  */
  80.  
  81. STDMETHODIMP SphereCameraClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
  82.   SphereCamera*      pObj = NULL;
  83.   HRESULT       hr;
  84.  
  85.   *ppvObj = NULL;
  86.   hr = ResultFromScode(E_OUTOFMEMORY);
  87.  
  88.   //Verify that a controlling unknown asks for IUnknown
  89.   if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
  90.       return ResultFromScode(E_NOINTERFACE);
  91.  
  92.   //Create the object passing function to notify on destruction.
  93.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExCamera))
  94.       pObj = new SphereCamera;
  95.   else
  96.       return ResultFromScode(E_NOINTERFACE);
  97.  
  98.   hr=pObj->QueryInterface(IID_I3DExCamera, ppvObj);
  99.  
  100.   //Kill the object if initial creation failed.
  101.   if (FAILED(hr))
  102.       delete pObj;
  103.   else
  104.       global_count_Obj++;
  105.  
  106.   return hr;
  107.   }
  108.  
  109.  
  110. /*
  111.  * SphereCameraClassFactory::LockServer
  112.  *
  113.  * Purpose:
  114.  *  Increments or decrements the lock count of the DLL.  If the
  115.  *  lock count goes to zero and there are no objects, the DLL
  116.  *  is allowed to unload.  See DllCanUnloadNow in "Shadrdll.cpp".
  117.  *
  118.  * Parameters:
  119.  *  fLock           BOOL specifying whether to increment or
  120.  *                  decrement the lock count.
  121.  *
  122.  * Return Value:
  123.  *  HRESULT         NOERROR always.
  124.  */
  125.  
  126. STDMETHODIMP SphereCameraClassFactory::LockServer(BOOL fLock) {
  127.   if (fLock)
  128.       global_count_Lock++;
  129.   else
  130.       global_count_Lock--;
  131.  
  132.   return NOERROR;
  133.   }
  134.  
  135.